package com.robotserver.orders.aop;

import com.robotserver.orders.common.vo.ResponseResult;
import com.robotserver.orders.constant.ResponseCode;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * Controller Aop
 * 获取响应结果信息
 * </p>
 */
@Aspect
@Component
public class WebResponseAop {

    private static Logger logger = LoggerFactory.getLogger(WebResponseAop.class);

    /**
     * 切点
     */
    private static final String POINTCUT = "execution(public * com.robotserver.orders.web..*.*(..))";

    /**
     * 默认的请求内容类型,表单提交
     **/
    private static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
    /**
     * JSON请求内容类型
     **/
    private static final String APPLICATION_JSON = "application/json";
    /**
     * GET请求
     **/
    private static final String GET = "GET";
    /**
     * POST请求
     **/
    private static final String POST = "POST";


    @Around(POINTCUT)
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        // 执行目标方法,获得返回值
        Object result = joinPoint.proceed();
        Object responseResult = null;
        try {
            responseResult = new ResponseResult(ResponseCode.SUCCESS,null, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return responseResult;
    }
}
